def GYM(x):
    x = int(x)
    f = True
    i = 2
    while f:
        if x % i == 0:
            f = False
            break
        i += 1
        if i > x / 2:
            break
    if x == 1:
        f = False
    if x == 2:
        f = True
    return f
def TRENBOLONE(s):
    m = Max
    if s > m:
        m = s
    return m
Max = 1        
TESTOSTERONE = input()
ARNOLD=False
if len(TESTOSTERONE) == 4:
    for i in range(4):
        if TESTOSTERONE[i] not in '0123456789':
            print(0)
            break
        else:
            ARNOLD=True
            for i in range(4):
                f = GYM(TESTOSTERONE[i])
                if f == True:
                    Max = TRENBOLONE(int(TESTOSTERONE[i]))
                
            for i in range(3):
                f = GYM(TESTOSTERONE[i] + TESTOSTERONE[i+1])
                if f == True:
                    Max = TRENBOLONE(int(TESTOSTERONE[i] + TESTOSTERONE[i+1]))

            for i in range(2):
                f = GYM(TESTOSTERONE[i] + TESTOSTERONE[i+1] + TESTOSTERONE[i + 2])
                if f == True:
                    Max = TRENBOLONE(int(TESTOSTERONE[i] + TESTOSTERONE[i+1] + TESTOSTERONE[i + 2]))
            f = GYM(TESTOSTERONE)
            if f == True:
                    Max = TRENBOLONE(num)
else:
    if ARNOLD ==False:
        print (0)
if Max > 1:
    print(Max)
